var e = require;
var t = module;
var o = exports;
Object.defineProperty(o, "__esModule", {value: !0});
o.ArchiveBase = void 0;
var n = function (e, t) {
        if ("_" !== e[0]) return t;
    },
    i = (function () {
        function e(e, t) {
            void 0 === t && (t = !1);
            this._def = {dirty: {}, timeId: {}, archiveKey: null};
            this._storeDuration = {};
            e && e.length > 0 && (this._def.archiveKey = e);
        }
        e.destroy = function () {
            if (this._instance) {
                this._instance.destroy();
                this._instance = null;
            }
        };
        e.prototype.setStoreTime = function (e, t) {
            this._storeDuration[e] = t;
        };
        e.prototype.saveData = function (e, t, o, i, r) {
            var a = this;
            void 0 === e && (e = this._def.archiveKey);
            void 0 === t && (t = this);
            void 0 === i && (i = !1);
            void 0 === r && (r = !1);
            if (e && 0 != e.length && (!this._def.dirty[e] || i)) {
                this._def.dirty[e] = !0;
                null != this._def.timeId[e] && clearTimeout(this._def.timeId[e]);
                this._def.timeId[e] = setTimeout(
                    function () {
                        "object" == typeof t && (t = JSON.stringify(t, o || n));
                        a.save(e, t);
                        r && a.sendServerDataData();
                        a._def.dirty[e] = !1;
                        a._def.timeId[e] = null;
                    },
                    i ? 0 : this._storeDuration[e] || 0
                );
            }
        };
        e.prototype.save = function (e, t) {
            cc.sys.localStorage.setItem(e, t);
        };
        e.prototype.sendServerDataData = function () {};
        e.prototype.chekcIsNull = function (e) {
            return null == e || null == e || "" == e;
        };
        e.prototype.readObj = function (e, t) {
            var o = cc.sys.localStorage.getItem(e);
            return this.chekcIsNull(o) ? t : JSON.parse(o);
        };
        e.prototype.loadData = function (e, t) {
            void 0 === e && (e = this._def.archiveKey);
            void 0 === t && (t = this);
            if (!e || 0 == e.length) return !1;
            var o = this.readObj(e, null);
            if (null == o) return !1;
            for (var n in o) {
                var i = o[n];
                t[n] = i;
            }
            return !0;
        };
        e.prototype.destroy = function () {
            for (var e in this._def.timeId) {
                var t = this._def.timeId[e];
                null != t && clearTimeout(t);
            }
            this._def.timeId = {};
            this._def.dirty = {};
            this._storeDuration = {};
        };
        e._instance = null;
        return e;
    })();
o.default = i;
o.ArchiveBase = i;
